// 引入mongoose模块
const mongoose = require('mongoose');

// 创建评论集合规则
const commentSchema = new mongoose.Schema({
  // 提交评论的用户
  user: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'User',
    required: true
  },
  // 评论内容
  content: {
    type: String,
    required: [true, '评论不能为空']
  },
  // 评论时间
	createAt: {
		type: Date,
		default: Date.now
  },
  // 回复人的评论id
  response: {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'Comment',
    default: null
  },
  level: {
    type: Number
  }
})

// 根据规则创建集合
const Comment = mongoose.model('Comment', commentSchema)

// 导出集合
module.exports = Comment